/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmChuyenKhoan2.java
 *
 * Created on Dec 16, 2011, 12:50:37 PM
 */
package Gui;

import AccessData.SqlServer;
import java.sql.ResultSet;
import java.util.Calendar;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.JOptionPane;
import sun.util.BuddhistCalendar;

/**
 *
 * @author User
 */
public class frmChuyenKhoan2 extends javax.swing.JFrame {

    String soThe;
    String atmID;
    String soTK;
    int tien;

    /** Creates new form frmChuyenKhoan2 */
    public frmChuyenKhoan2() {
        initComponents();
    }

    public frmChuyenKhoan2(String soThe, String atmID, String soTK, int tien) {
        initComponents();
        this.soThe = soThe;
        this.atmID = atmID;
        this.soTK = soTK;
        this.tien = tien;
        this.lblTKNhan.setText(soTK);
        this.HienThi();
        //this.lblSoTien.add(tien);
    }

    public Vector getParam() {
        Vector v = new Vector();

        v.add(soThe);
        v.add(soTK);
        v.add(atmID);

        Calendar cal = new BuddhistCalendar();
        StringTokenizer st = new StringTokenizer(cal.getTime().toString(), " ");
        st.nextToken();
        String ngay = st.nextToken();
        ngay += "/" + st.nextToken();
        String gio = st.nextToken();
        st.nextToken();
        ngay += "/" + st.nextToken();

        v.add(ngay);
        v.add(gio);

        v.add(tien);
        return v;
    }

    public void HienThi() {
        String Query = "Select pHoTen From Person,Account Where Person.pID = Account.pID and Account.aSoTK like " + soTK;
        String user = "";
        SqlServer sql = new SqlServer();
        ResultSet rs = null;
        try {
            rs = sql.executeQuery(Query);
            rs.first();
            user = rs.getString(1);
        } catch (Exception e) {
            System.out.println("Erro " + e.getMessage());
        }
        this.lblNguoiNhan.setText(user);
        String T = "" + tien + " VND";
        this.lblSoTien.setText(T);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblTKNhan = new javax.swing.JLabel();
        lblNguoiNhan = new javax.swing.JLabel();
        lblSoTien = new javax.swing.JLabel();
        btnOK = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Chi tiết chuyển khoản");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setForeground(new java.awt.Color(204, 0, 0));
        jLabel1.setText("Chi tiết giao dịch chuyển khoản");

        jLabel2.setText("Số tài khoản nhận:");

        jLabel3.setText("Tên người nhận:");

        jLabel4.setText("Số tiền chuyển:");

        lblTKNhan.setText("jLabel5");

        lblNguoiNhan.setText("jLabel6");

        lblSoTien.setText("jLabel7");

        btnOK.setText("Đồng ý");
        btnOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOKActionPerformed(evt);
            }
        });

        btnCancel.setText("Hủy bỏ");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(71, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(62, 62, 62))
            .addGroup(layout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(44, 44, 44)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblSoTien)
                    .addComponent(lblNguoiNhan)
                    .addComponent(lblTKNhan))
                .addContainerGap(200, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(129, 129, 129)
                .addComponent(btnOK)
                .addGap(18, 18, 18)
                .addComponent(btnCancel)
                .addContainerGap(136, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addComponent(jLabel1)
                .addGap(46, 46, 46)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(lblTKNhan))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(lblNguoiNhan))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(lblSoTien))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancel)
                    .addComponent(btnOK))
                .addContainerGap(61, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
// TODO add your handling code here:
    SqlServer sql = new SqlServer();
    int rs = Integer.MIN_VALUE;
    try {
        rs = sql.executeProc("sp_ChuyenKhoan", this.getParam());
    } catch (Exception e) {
        System.out.println("Erro " + e.getMessage());
    }
    if (rs != Integer.MIN_VALUE) {
        frmLoaiGD gd = new frmLoaiGD(soThe, atmID);
        this.dispose();
        gd.setVisible(true);
    }
    else JOptionPane.showMessageDialog(null,"Giao dich bi loi");
}//GEN-LAST:event_btnOKActionPerformed

private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
// TODO add your handling code here:
    this.dispose();
    frmLoaiGD gd = new frmLoaiGD(soThe, atmID);
    gd.setVisible(true);
}//GEN-LAST:event_btnCancelActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmChuyenKhoan2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmChuyenKhoan2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmChuyenKhoan2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmChuyenKhoan2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frmChuyenKhoan2().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnOK;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel lblNguoiNhan;
    private javax.swing.JLabel lblSoTien;
    private javax.swing.JLabel lblTKNhan;
    // End of variables declaration//GEN-END:variables
}
